<template>
	<view class="logins">
		<nav-bar isBack  title="地址管理" ></nav-bar>
		<view class="box" v-for="(item,index) in list" :key="index" >
			<radio @click="addressClick(item,index)" @checked="index==selectIndex" color="#C3AB7C" data-index="index" data-select="index!=selectIndex"
			v-if="isSelect"></radio>
			<view :class="{radioactove:isSelect}">
				<view class="name">{{item.name}} {{item.mobile}}
					<p v-if="item.is_default==1">默认</p>
				</view>
				<view class="address">{{item.province}}{{item.city}}{{item.area}}</view>
				<view>{{item.address}}</view>
			</view>
			<i @click="editAddress(item.id)" class="iconfont icon-bianji" data-index="index"></i>
		</view>
		<view class="no-card" v-if="!list.length">
			<image src="https://manager.ryz1620.com/static/my/icon_address.png"></image>
			<view class="no-title">居然还没有收货地址</view>
			<text>快递，为生活添加动力~</text>
			<navigator class="no-bnt" :url="`/pages_mine/pages/my/address/edit?sourceFrom=${sourceFrom}&isSelect=${isSelect}&type=${type}`">新增一个</navigator>
		</view>
		<view style="height:120rpx"></view>
		<navigator class="bnt" :url="`/pages_mine/pages/my/address/edit?sourceFrom=${sourceFrom}&isSelect=${isSelect}&type=${type}`"> + 新增收货地址</navigator>
			
	</view>
</template>

<script>
import navBar from "@/components/navBar/navBar.vue"
import service_enter from '@/service/address.js'
import URL from '@/config/url.js'


export default {
	components: { navBar },
	
	data() {
		return {
			sourceFrom: 0,
			isSelect: '',
			list: [],
			selectIndex:'',
			type:'',
			singleOrder:'', //清单订单选择地址
		}
	},
	onLoad(option) {
		this.$utils.getUrl()
		this.type = option.type
		if (option.sourceFrom) {
			this.sourceFrom = option.sourceFrom;
		}
		if (option.isSelect) {
			this.isSelect = option.isSelect;
		}
		if(option.singleOrder){
			this.singleOrder = option.singleOrder
		}
		console.log(option)
	},
	onShow() {
		this.gitAddress()
	},
	methods: {
		editAddress(id) {
			if(this.type == ''){
				uni.navigateTo({
					url: `/pages_mine/pages/my/address/edit?id=${id}`
				});
			}else{
				uni.navigateTo({
					url: `/pages_mine/pages/my/address/edit?id=${id}&sourceFrom=${this.sourceFrom}&isSelect=${this.isSelect}&type=${this.type}`
				});
			}
			
		},
		gitAddress() {
			uni.showLoading({
			    title: '加载中...',
				mask: true
			})
			service_enter.getlist({
			}).then(res => {
				uni.hideLoading();
				if (res.code == 1) {
					this.list = res.data
				} else {
					uni.showToast({
						title: res.message,
						icon: "none"
					});
				}
			}).catch(err => {
	
			})
		},
		addressClick(item,index) {
			if (this.isSelect) {
				if(this.singleOrder){
					let pages = getCurrentPages();  //获取所有页面栈实例列表
					console.log(pages)
					let nowPage = pages[ pages.length - 1];  //当前页页面实例
					let prevPage = pages[ pages.length - 2 ];  //上一页页面实例
					prevPage.$vm.addressInfo = item;
					uni.navigateBack({
						delta: 1
					});
				}else{
					this.selectIndex = index
					if(this.type == 1){
						uni.navigateTo({
							url:`/pages_mall/pages/mall/order/order?sourceFrom=${this.sourceFrom}&isSelect=${this.isSelect}&id=${item.id}`
						})
					}else{
						uni.navigateTo({
							url:`/pages_mall/pages/mall/order/order?sourceFrom=${this.sourceFrom}&isSelect=${this.isSelect}&id=${item.id}&buy_type=${this.type}`
							//url:`/pages_product/pages/product/order/order?sourceFrom=${this.sourceFrom}&isSelect=${this.isSelect}&id=${item.id}&buy_type=${this.type}`
						})
					}
				}
				
			}
		}
	}
}
</script>

<style lang="scss" scoped>
.logins{
	width: 100vw;min-height: 100vh;background: #fff;display: flex;flex-flow: column;
}
.icon-bianji{
	background: url(@/static/my/bianji.png) no-repeat center center;
	background-size: 55%;
}
.box {
		font-size: 26rpx;
		    color: #999;
		    position: relative;
		    padding: 30rpx 20rpx;
		    margin: 0 20rpx;
		    border-bottom: 1px #f5f5f5 solid;
	}

	.name {
		font-size: 30rpx;
		color: #000;
	}

	p {
		display: inline-block;
		background-color: red;
		color: #fff;
		font-size: 20rpx;
		border-radius: 8rpx;
		padding: 4rpx 10rpx;
		margin-left: 10rpx;
	}

	.address {
		padding-top: 20rpx;
		padding-bottom: 10rpx;
	}

	.icon-bianji {
		color: #999;
		position: absolute;
		top: 20rpx;
		right: 0rpx;
		z-index: 9;
		width: 70rpx;
		height: 70rpx
	}

	.bnt {
		position: fixed;
		bottom: 0;
		right: 0;
		left: 0;
		z-index: 2;
		height: 80rpx;
		background-color: #C3AB7C;
		color: #fff;
		text-align: center;
		line-height: 80rpx;
		font-size: 30rpx;
		margin: 20rpx;
		border-radius: 50rpx;
	}

	.no-card {
		background-color: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		border-radius: 20rpx 20rpx 0 0;
		padding-top: 40rpx;
	}

	.no-title {
		padding: 30rpx 0;
	}

	.no-card>text {
		font-size: 24rpx;
		color: #999;
	}

	.no-bnt {
		padding: 10rpx 20rpx;
		margin: 20rpx;
		border: 2rpx solid #eee;
		font-size: 26rpx;
	}

	.no-card image {
		height: 160rpx;
		width: 160rpx;
		background-color: #f6f6f6;
		border-radius: 50%;
		padding: 40rpx;
	}
    .radioactove{
		padding-left: 80rpx;
	}
	radio {
		position: absolute;
		left: 20rpx;
		top: 50%;
		margin-top: -20rpx;
	}
</style>